//
//  GMFColorButton.m
//  SplunkMobile
//
//  Created by lijunying on 2/26/2016.
//  Copyright © 2016 Gome. All rights reserved.
//

#import "GMFColorButton.h"

@implementation GMFColorButton



- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
//        NSLog(@"sss %d", _intRadius);
    }
    
    return self;
}

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
//    [self createACircleWithRadius:_intRadius AndColor:_clrCircle];
    [self createACircleWithRadius:_intRadius AndColor:_clrCircle];
}

- (void)setRadius:(NSInteger)radius andColor:(UIColor *)color
{
    _intRadius = radius;
    _clrCircle = color;
}

- (void)setRadius:(NSInteger)radius andColor:(UIColor *)color andHeight:(BOOL)isHeightNeeded
{
    _intRadius = radius - 3;
    _clrCircle = color;
    _isBottomIcon = isHeightNeeded;
}


- (void)createACircleWithRadius:(NSInteger)radius AndColor:(UIColor *)color
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    if (_isBottomIcon)
    {
        CGContextAddEllipseInRect(context, CGRectMake((self.frame.size.width - radius * 2) * 0.5, (self.frame.size.height - radius * 2) * 0.5 - 7, radius * 2, radius * 2));
    }
    else
        CGContextAddEllipseInRect(context, CGRectMake((self.frame.size.width - radius * 2) * 0.5, (self.frame.size.height - radius * 2) * 0.5, radius * 2, radius * 2));
//    CGContextAddEllipseInRect(context, CGRectMake(0, 0, 18, 18));
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillPath(context);
}


- (void)selectOrUnselectTheButton:(BOOL)isSelected
{
    if (isSelected)
    {
        _intRadius = intLargerCircleRadius;
    }
    else
    {
        _intRadius = intNormalCircleRadius;
    }
    
    [self setNeedsDisplay];
}


- (void)changeButtonColor:(UIColor *)color
{
    _clrCircle = color;
    
    [self setNeedsDisplay];
}


@end
